package com.lifesting.front;

import java.io.IOException;
import java.util.Map;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import com.sun.faces.renderkit.html_basic.HtmlBasicRenderer;
//默认行为，仅显示它的子component
public class ColumnRender extends HtmlBasicRenderer {
	public static final String RENDER_TYPE = "com.lifesting.render.column";
	@Override
	public void encodeBegin(FacesContext context, UIComponent component)
			throws IOException {
		super.encodeBegin(context, component);
		ResponseWriter writer = context.getResponseWriter();
		writer.startElement("td", component);
		
	}
	@Override
	public void encodeEnd(FacesContext context, UIComponent component)
			throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		
		writer.endElement("td");
	}
	@Override
	public void decode(FacesContext context, UIComponent component) {
		//如果发现有当前列ID+".1"，更新sortOrder
		super.decode(context, component);
		String my_id = component.getClientId(context);
		Map<String, String> req_map = context.getExternalContext().getRequestParameterMap();
		if (req_map.containsKey(my_id+".1.x") && req_map.containsKey(my_id+".1.y")){
			Column mc = (Column) component;
			Integer v = mc.getSortOrder()*(-1) ;
			if (v == 0) v = 1;
			mc.setSortOrder(v);
		}
	}
}
